﻿function color(obj, type) {
    var spClass = $(obj).find("span").attr("class");
    
  
    if (type == "car") {
    	var cartype;
        if (spClass == "switch-on") {
        	cartype ="有车"
            $("#divNoCar").css("color", "#dbdbdb");
            $("#divHaveCar").css("color", "#333");
        } else {
        	cartype ="无车";
            $("#divHaveCar").css("color", "#dbdbdb");
            $("#divNoCar").css("color", "#333");
        }
        $.ajax({
            cache : false,
            async:false, 
            url : "/getcarhouseinfo",
            data : {"cartype":cartype},
            success:function(data){
            }
        });
        

    } else {
    	  var housetype;
        if (spClass == "switch-on") {
        	housetype ="有房";
            $("#divNoHouse").css("color", "#dbdbdb");
            $("#divHaveHouse").css("color", "#333");
        } else {
        	housetype ="无房";
            $("#divHaveHouse").css("color", "#dbdbdb");
            $("#divNoHouse").css("color", "#333");
        }
        
        $.ajax({
            cache : false,
            async:false, 
            url : "/getcarhouseinfo",
            data : {"housetype":housetype},
            success:function(data){
            }
        });
    }
    


}

$(function () {

    $("#btnNext").click(function () {

        var spNumber = 1;
        $(".menu-all").children().each(function (index) {
            var divDispaly = $(this).css("display");
            if (divDispaly == "block") {
                spNumber = parseInt(spNumber) + index;
                
                var pageevent ="";
                if(spNumber==1){
                	pageevent="家庭结构";
                }
                if(spNumber==2){
                	pageevent="家庭收入";
                }
                if(spNumber==3){
                	pageevent="有车有房吗";
                }
                
                if(pageevent !=""){
                	   $.ajax({
                           cache : false,
                           async:false, 
                           url : "/geteventinfobytable",
                           data : {"eventname":pageevent},
                           success:function(data){
                           }
                       });
                }
             
                
                
                
            
            }

        });
        if (spNumber == 1) {
            var manImg = $(".manImg").attr("src");
            var womanImg = $(".womanImg").attr("src");
            if (manImg == "/static/images/icon_man@2x.png" && womanImg == "/static/images/icon_wom@2x.png") {
                return;
            }
        }
   
        $(".menu-all").children().css("display", "none");
        $(".menu-all").children().eq(parseInt(spNumber)).css("display", "block");
        if (parseInt(spNumber) > 3) {
            window.location.href = "/result";
        }else {
            $("#spNumber").text(parseInt(spNumber) + 1)
        }
        
    });

    $("#btnLast").click(function () {
        var spNumber = parseInt($("#spNumber").text());
        if (spNumber == 1) {
            window.location.href = "/index";
            return;
        }

        $(".menu-all").children().each(function (index) {
            var divDispaly = $(this).css("display");
            if (divDispaly == "block") {
                spNumber = index;
                var pageevent ="";
                if(spNumber==1){
                	pageevent="男左女右";
                }
                if(spNumber==2){
                	pageevent="家庭结构";
                }
                if(spNumber==3){
                	pageevent="家庭收入";
                }
                if(spNumber==4){
                	pageevent="有车有房吗";
                }
               
                if(pageevent !=""){
                	   $.ajax({
                           cache : false,
                           async:false, 
                           url : "/geteventinfobytable",
                           data : {"eventname":pageevent},
                           success:function(data){
                           }
                       });
                }
                
                
                
                
                
                 
            }

        });
        $(".menu-all").children().css("display", "none");
        $(".menu-all").children().eq(parseInt(spNumber) - 1).css("display", "block");
        $("#spNumber").text(parseInt(spNumber))

    });

    $(".manImg").click(function () {
        $(this).attr("src", "/static/images/icon_manz@2x.png");
        $(".womanImg").attr("src", "/static/images/icon_wom@2x.png");
        $("#btnNext").css("background-color", "#1b4695");
    });

    $(".womanImg").click(function () {
        $(this).attr("src", "/static/images/icon_womz@2x.png");
        $(".manImg").attr("src", "/static/images/icon_man@2x.png");
        $("#btnNext").css("background-color", "#1b4695");
    });

    $("#divDsgz").click(function () {
        $(this).attr("class", "single familydiv fl active");
        $("#divYhyw").attr("class", "marriedChild familydiv fr");
    });

    $("#divYhyw").click(function () {
        $(this).attr("class", "marriedChild familydiv fr active");
        $("#divDsgz").attr("class", "single familydiv fl");
    });



})